﻿using Dln.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.Redis;
using System.Configuration;
using Dln.Handler;

namespace Dln.Handler
{
    public class MessageHelper
    {

        /// <summary>
        /// 发送住院信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="title"></param>
        /// <param name="time"></param>
        /// <param name="number"></param>
        /// <param name="remark"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public static string OrderPayNotice(string openId, string title, string time, string number, string remark, string link)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", WeiXinConfig.AccessToken);
            string temp = "{\"touser\":\"" + openId + "\"," +
                                   "\"template_id\":\"" + CommonHelper.GetAppSettings("InHospitalInfo") + "\"," +
                                    "\"url\":\"" + link + "\"," +
                                   "\"topcolor\":\"#d4a93a\"," +
                                   "\"data\":{" +
                                           "\"first\": {" +
                                               "\"value\":\"" + title + "\"," +
                                               "\"color\":\"#239f3d\"" +
                                           "}," +
                                           "\"keyword1\":{" +
                                               "\"value\":\"" + time + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "}," +
                                           "\"keyword2\": {" +
                                               "\"value\":\"" + number + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "}," +
                                           "\"remark\": {" +
                                               "\"value\":\"" + remark + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "} " +
                                   "}" +
                               "}";
            return RequestHelper.SendPost(url, temp);
        }


        /// <summary>
        /// 发送报修信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="title"></param>
        /// <param name="time"></param>
        /// <param name="number"></param>
        /// <param name="remark"></param>
        /// <param name="link"></param>
        /// <returns></returns>
        public static string ProblemNotice(string openId, string title, string time, string number, string remark, string link)
        {
            string url = string.Format("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}", WeiXinConfig.AccessToken);
            string temp = "{\"touser\":\"" + openId + "\"," +
                                   "\"template_id\":\"" + CommonHelper.GetAppSettings("Problem") + "\"," +
                                    "\"url\":\"" + link + "\"," +
                                   "\"topcolor\":\"#d4a93a\"," +
                                   "\"data\":{" +
                                           "\"first\": {" +
                                               "\"value\":\"" + title + "\"," +
                                               "\"color\":\"#239f3d\"" +
                                           "}," +
                                           "\"keyword1\":{" +
                                               "\"value\":\"" + time + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "}," +
                                           "\"keyword2\": {" +
                                               "\"value\":\"" + number + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "}," +
                                           "\"remark\": {" +
                                               "\"value\":\"" + remark + "\"," +
                                               "\"color\":\"#0A0A0A\"" +
                                           "} " +
                                   "}" +
                               "}";
            return RequestHelper.SendPost(url, temp);
        }

    }
}
